{block name=student}

{function name=setstudentclass id="" default="0"}{assign var=val value=$default}{if $id neq ""}{foreach from=$student.cartitem_id key=key item=value}{if $id eq $key}{assign var=val value=$value}{break}{/if}{/foreach}{/if}{$val}{/function}

{function name=setstudentclasschk id="" default="0"}{assign var=val value=$default}{if $id neq ""}{foreach from=$student.cartitem_id key=key item=value}{if $id eq $key}{assign var=val value=$value}{break}{/if}{/foreach}{/if}{if $val eq 1}checked{/if}{/function}

{if $cnt} {assign var='cnt' value=$cnt+1} {else} {assign var='cnt' value=1} {/if}
<div id="student{$cnt}" class="students{if $student.student_id} existing-student{else} new-student{/if}" data-fullname="{$student.student_name|lower} {$student.student_surname|lower}">
    <input type="hidden" name="student[{$cnt}][student_id]" value="{$student.student_id}" />
    <input type="hidden" name="student[{$cnt}][student_trial_flag]" id="trial{$cnt}" value="{if $student.student_trial_flag}{$student.student_trial_flag}{else}0{/if}" /> {if $student.student_id}
    <!-- EXISTING STUDENT  -->
    <input type="hidden" name="student[{$cnt}][student_name]" value="{$student.student_name}" class="" />
    <input type="hidden" name="student[{$cnt}][student_surname]" value="{$student.student_surname}" />
    <input type="hidden" name="student[{$cnt}][student_sex]" value="{$student.student_sex}" />
    <input type="hidden" name="student[{$cnt}][student_dob]" value="{$student.student_dob}" id="dob{$cnt}" />
    <input type="hidden" name="student[{$cnt}][student_medical]" value="{$student.student_medical}" /> 您希望 <b>{$student.student_name}</b> 报名参加哪个课程？
    <br>
    <!--<small>{$student.student_dob|date_format:'%d %B %Y'}</small><br>-->
    <small>{$student.student_medical}</small>
    <div class="row form-group">
        {if is_array($preSelected) && $preSelected[$student.student_id][$item.term_object_id][$item.class_object_id] eq 1 }{assign var='preSelectOneClass' value=1}{/if} {foreach $productsOnCart as $item} {if $item.cartitem_class_flag eq 1}
        <div class="col-sm-12">
            {if $student.student_id && $item.cartitem_enrolment_type eq 'T'}
            <label class="text-disabled">
                <input type="hidden" value="" name="stdnotrial">
                <input class="chckbx" disabled="disabled" type="checkbox">
                <small>{$item.cartitem_product_name}</small>
                <div class="small text-danger">该学生不符合体验课程资格</div>
            </label>
            {else}
            <label>
                <input type="hidden" value="{if $selectedStudent[$student.student_id][$item.cartitem_product_id]}1{else}{call name=setstudentclass id=$item.cartitem_id default=$preSelectOneClass}{/if}" name="student[{$cnt}][cartitem_id][{$item.cartitem_id}]" class="value">
                <!-- REMOVED 04/05/2015 [CheckSelectedClasses(this);] <input class="chckbx classterm-chk" data-cnt="{$cnt}" data-min-age="{$item.agegroup_min}" data-max-age="{$item.agegroup_max}" data-cartitem="{$item.cartitem_id}" data-quantity="{$item.cartitem_quantity}" type="checkbox" {if $selectedStudent[$student.student_id][$item.cartitem_product_id]}checked{else}{call name=setstudentclasschk id=$item.cartitem_id}{/if} name="ct-checkbox" onchange="CheckSelectedClasses(this); if($(this).is(':checked')){ $(this).parent().children('.value').val('1'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('1');{/if} }else{ $(this).parent().children('.value').val('0'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('0');{/if} }" > -->
                <input class="chckbx classterm-chk" data-cnt="{$cnt}" data-min-age="{$item.agegroup_min}" data-max-age="{$item.agegroup_max}" data-cartitem="{$item.cartitem_id}" data-quantity="{$item.cartitem_quantity}" type="checkbox" {if $selectedStudent[$student.student_id][$item.cartitem_product_id]}checked{else}{call name=setstudentclasschk id=$item.cartitem_id default=$preSelectOneClass}{/if} name="ct-checkbox" onchange="if($(this).is(':checked')){ $(this).parent().children('.value').val('1'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('1');{/if} }else{ $(this).parent().children('.value').val('0'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('0');{/if} }">
                <small>{$item.cartitem_product_name}</small>
            </label>
            {/if}
        </div>
        {/if} {/foreach}
    </div>
    {else}
    <!-- NEW STUDENT  -->
    <div class="fake-student {if $student.student_name neq ''}saveFake{/if}" {if $student.student_name eq ''}style="display:none" {/if}>
        您希望 <b>{$student.student_name} {$student.student_surname}</b> 报名参加哪个课程？ <a href="javascript:EditStudent('student{$cnt}')">编辑学生信息</a>
        <br>
        <!--<small>{$student.student_dob|date_format:'%d %B %Y'}</small><br>-->
        <small>{$student.student_medical}</small>
        <div class="row form-group">
            {if count($productsOnCart) eq 1 }{assign var='preSelectOneClass' value=1}{/if} {foreach $productsOnCart as $item} {if $item.cartitem_class_flag eq 1 && ( ($item.cartitem_enrolment_type eq 'S') || (!$student.student_id && $item.cartitem_enrolment_type eq 'T') )}
            <div class="col-sm-12">
                <label>
                    <input type="hidden" value="{if $selectedStudent[$student.student_id][$item.cartitem_product_id]}1{else}{call name=setstudentclass id=$item.cartitem_id default=$preSelectOneClass}{/if}" name="student[{$cnt}][cartitem_id][{$item.cartitem_id}]" class="value">
                    <!-- REMOVED 04/05/2015 [CheckSelectedClasses(this);] <input class="chckbx classterm-chk {$item.cartitem_enrolment_type}" data-cnt="{$cnt}" data-min-age="{$item.agegroup_min}" data-max-age="{$item.agegroup_max}" data-cartitem="{$item.cartitem_id}" data-quantity="{$item.cartitem_quantity}" type="checkbox" {if $selectedStudent[$student.student_id][$item.cartitem_product_id]}checked{else}{call name=setstudentclasschk id=$item.cartitem_id default=1}{/if} name="ct-checkbox" onchange="CheckSelectedClasses(this); if($(this).is(':checked')){ $(this).parent().children('.value').val('1'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('1');{/if} }else{ $(this).parent().children('.value').val('0'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('0');{/if} }" > -->
                    <input class="chckbx classterm-chk {$item.cartitem_enrolment_type}" data-cnt="{$cnt}" data-min-age="{$item.agegroup_min}" data-max-age="{$item.agegroup_max}" data-cartitem="{$item.cartitem_id}" data-quantity="{$item.cartitem_quantity}" type="checkbox" {if $selectedStudent[$student.student_id][$item.cartitem_product_id]}checked{else}{call name=setstudentclasschk id=$item.cartitem_id default=$preSelectOneClass}{/if} name="ct-checkbox" onchange="if($(this).is(':checked')){ $(this).parent().children('.value').val('1'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('1');{/if} }else{ $(this).parent().children('.value').val('0'); {if $item.cartitem_enrolment_type eq 'T'}$('#trial{$cnt}').val('0');{/if} }">
                    <small>{$item.cartitem_product_name}</small>
                </label>
            </div>
            {/if} {/foreach}
        </div>
    </div>
    <div class="addstuform" {if $student.student_name neq ''} style="display:none" {/if}>
        <h2 class="title">添加新学生</h2>
        <div id="enroltrialmain" class="addnew">
            <div class="row">
                <div class="col-sm-8 col-sm-offset-2">
                    <div class="row">
                        <div class="col-sm-6 form-group">
                            <label>* 姓名:</label>
                            <input type="text" value="{$student.student_name}" class="form-control new_name" id="gname{$cnt}" name="student[{$cnt}][student_name]" required>
                        </div>
                        <div class="col-sm-6 form-group">
                            <label>* 性别:</label>
                            <input type="hidden" value="{$student.student_surname}" class="form-control new_surname" id="surname{$cnt}" name="student[{$cnt}][student_surname]">
                            <select name="student[{$cnt}][student_sex]" class="form-control" required>
                                <option value="1" {if $student.student_sex eq 1}selected="selected" {/if}>男孩</option>
                                <option value="2" {if $student.student_sex eq 2}selected="selected" {/if}>女孩</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12 col-md-6 form-group">
                            <label>* 生日:</label>
                            <!-- <input class="form-control dates datepicker" type="text" value="{if $student.student_dob && $student.student_dob neq '0000-00-00'}{$student.student_dob|date_format:'%d/%m/%Y'}{/if}" name="from{$cnt}" id="from{$cnt}" onchange="setDateValue('dob{$cnt}',this.value);" > -->
                            <input type="hidden" value="{$student.student_dob}" name="student[{$cnt}][student_dob]" id="dob{$cnt}">
                            <div>
                                <span class="form-group to">
								<select id="dobyear{$cnt}" name="year" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
									<option value="">年</option>
									{assign var=initYear value='Y'|date}
									{for $year=$initYear-10 to $initYear-2}
										<option value="{$year}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%Y' eq $year}selected="selected"{else}{if $search.year eq $year}selected="selected"{/if}{/if}>{$year} 年</option>
									{/for}
								</select>
							</span>
                                <span class="form-group ts" id="monthout">
								<select id="dobmonth{$cnt}" name="month" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
										<option value="">月</option>
										{for $month=1 to 12}
										<option value="{if $month lt 10}0{/if}{$month}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%m' eq $month}selected="selected"{else}{if $search.month eq $month}selected="selected"{/if}{/if}>{$month} 月</option>
										{/for}
								</select>
							</span>
                                <span class="form-group ts">
								<select id="dobday{$cnt}" name="day" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
									<option value="">日</option>
									{for $day=1 to 31}
										<option value="{if $day lt 10}0{/if}{$day}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%d' eq $day}selected="selected"{else}{if $search.day eq $day}selected="selected"{/if}{/if}>{$day} 日</option>
									{/for}
								</select>
							</span>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12 form-group">
                            <label>身体状况:</label>
                            <textarea class="form-control" name="student[{$cnt}][student_medical]">{$student.student_medical}</textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6 form-group hidden-xs">
                            <button type="button" class="enquire" onclick="CancelAddStudent('student{$cnt}')">取消</button>
                        </div>
                        <div class="col-sm-6 form-group">
                            <button type="button" class="enquire" onclick="if($(this).closest('form').valid()) SaveStudent('student{$cnt}')">继续</button>
                        </div>
                        <div class="col-sm-6 form-group visible-xs">
                            <button type="button" class="enquire" onclick="CancelAddStudent('student{$cnt}')">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {/if}
</div>
{/block}
